package persistence;

final public class City {
	private int id;
	private int zipCode;
	private String name;
	
	protected City() {}
	
	protected City(int id) {
		setId(id);
	}
	
	protected City(int id, int zipCode, String name) {
		setId(id);
		setZipCode(zipCode);
		setName(name);
	}	
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + zipCode;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		City other = (City) obj;
		if (id != other.id)
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (zipCode != other.zipCode)
			return false;
		return true;
	}
	
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("City: ").append("id: ").append(id).append(", zipCode: ").append(zipCode)
		.append(", name: ").append(name);
		
		return builder.toString();
	}

	public int getId() {
		return id;
	}
	public int getZipCode() {
		return zipCode;
	}
	public String getName() {
		return name;
	}
	public void setId(int id) {
		this.id = id;
	}
	public void setZipCode(int zipCode) {
		this.zipCode = zipCode;
	}
	public void setName(String name) {
		this.name = name;
	}	
}
